home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / ssavwin.exe / SPOTSAVR.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-04-29  |  5.7 KB  |  124 lines

  1. {****************************************************************************
  2. *                                                                           *
  3. *  SpotSavr.pas: Plug-in animation module for SSaveDem.pas                  *
  4. *                                                                           *
  5. *  Rev. 0.1   19.4.93   MK  IR                                              *
  6. *                                                                           *
  7. ****************************************************************************}
  8.  
  9. { Name for this Screen Saver - shows up in Control Panel: }
  10. {$D SCRNSAVE Spotlight }
  11.  
  12. const AppName: PChar = 'Screen Saver.Spotlight' ;
  13.  
  14. type
  15.   PMySaverWin = ^TMySaverWin;
  16.   TMySaverWin = Object(TScSaverWin)
  17.     zx, zy, cx, cy, vx, vy, d: integer;
  18.     Desktop: hBitmap;
  19.     procedure SetupWindow; virtual;
  20.     procedure DoTheShow; virtual;
  21.     destructor Done; virtual;
  22.   end;
  23.  
  24. {****************************************************************************
  25. *                                                                           *
  26. *              T M y S a v e r W i n . S e t u p W i n d o w                *
  27. *                                                                           *
  28. *  OUTPUT: zx, zy = screen dimensions                                       *
  29. *          vx, vy = speed of spotlight                                      *
  30. *          cx, cy = starting position                                       *
  31. *          d      = spotlight diameter  (all of the above in pixels)        *
  32. *          Desktop= bitmap with copy of actual desktop picture              *
  33. *                                                                           *
  34. ****************************************************************************}
  35.  
  36. procedure TMySaverWin.SetupWindow;
  37.  
  38. var WinDC, MemDC: hDC;
  39.  
  40. begin
  41. inherited SetupWindow;
  42. zx := GetSystemMetrics (SM_CXSCREEN) ;        { get screen dimensions }
  43. zy := GetSystemMetrics (SM_CYSCREEN) ;
  44. randomize;
  45. cx := random (zx div 2) + 1;                  { get starting position }
  46. cy := random (zy div 2) + 1;
  47. vx := -1 + 2*random (2);                      { get speed: }
  48. vy := -1 + 2*random (2);                      { vx, vy = 1 or -1 }
  49. d  := zy div 4;                               { diameter }
  50.  
  51. WinDC := TestHandle (GetDC (hWindow));          { copy actual video RAM.. }
  52. MemDC := TestHandle (CreateCompatibleDC (WinDC));
  53. Desktop := TestHandle (CreateCompatibleBitmap (WinDC, zx, zy));
  54. TestHandle (SelectObject (MemDC, Desktop));
  55. TestBool (BitBlt (MemDC, 0, 0, zx, zy, WinDC, 0, 0, SRCCOPY));
  56. DeleteDC (MemDC);
  57. ReleaseDC (hWindow, WinDC);                      {..into bitmap "desktop" }
  58.  
  59. end;   { SetupWindow }
  60.  
  61.  
  62. {****************************************************************************
  63. *                                                                           *
  64. *              T M y S a v e r W i n . D o T h e S h o w                    *
  65. *                                                                           *
  66. *  INPUT:  zx, zy = screen dimensions                                       *
  67. *          vx, vy = speed of spotlight                                      *
  68. *          cx, cy = actual spotlight position                               *
  69. *          d      = spotlight diameter  (all of the above in pixels)        *
  70. *          Desktop= bitmap with copy of actual desktop picture              *
  71. *                                                                           *
  72. *  OUTPUT: vx, vy = new speed of spotlight                                  *
  73. *          cx, cy = new actual position                                     *
  74. *                                                                           *
  75. ****************************************************************************}
  76.  
  77. procedure TMySaverWin.DoTheShow ;
  78.  
  79. var WinDC, MemDC: hDC;
  80.     CircleRgn, BackGndRgn: hRgn;
  81.  
  82. begin
  83. WinDC := TestHandle (GetDC (hWindow));
  84. MemDC := TestHandle (CreateCompatibleDC (WinDC));
  85. TestHandle (SelectObject (MemDC, Desktop));  { get a DC with desktop bitmap }
  86.  
  87. if ((cx <= 0) or (cx+d >= zx)) then vx := -vx;      { bounce light at edges }
  88. if ((cy <= 0) or (cy+d >= zy)) then vy := -vy;
  89. cx := cx+vx;                                       { calculate new position }
  90. cy := cy+vy;
  91.  
  92. { Build the "spotlight region" that is to receive (part of) the bitmap: }
  93. CircleRgn := TestHandle (CreateEllipticRgn (cx, cy, cx+d, cy+d));
  94. { Build a rectangle region that's a bit bigger than the spotlight circle: }
  95. BackGndRgn := TestHandle (CreateRectRgn (cx-2, cy-2, cx+d+2, cy+d+2));
  96. { Subtract the circle region from the rectangle region: }
  97. TestHandle (CombineRgn (BackGndRgn, BackGndRgn, CircleRgn, RGN_DIFF));
  98. { Paint BackGndRgn black: this will erase the area surrounding the spotlight: }
  99. TestBool (FillRgn (WinDC, BackGndRgn, GetStockObject (black_brush)));
  100.  
  101. TestHandle (SelectObject (WinDC, CircleRgn));              { clipping region }
  102. TestBool (BitBlt (WinDC, 0, 0, zx, zy, MemDC, 0, 0, SRCCOPY));
  103.                                                      { copy bitmap -> screen }
  104.  
  105. DeleteDC (MemDC);
  106. ReleaseDC (hWindow, WinDC);
  107. DeleteObject (CircleRgn);
  108. DeleteObject (BackGndRgn);
  109. end;  { DoTheShow }
  110.  
  111. {****************************************************************************
  112. *                                                                           *
  113. *                  T M y S a v e r W i n . D o n e                          *
  114. *                                                                           *
  115. ****************************************************************************}
  116.  
  117. destructor TMySaverWin.Done;   { cleans up }
  118. begin
  119. DeleteObject (Desktop);
  120. inherited done;
  121. end;
  122.  
  123.  
  124.